package com.feizhou.oauth.dao;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.feizhou.oauth.bean.UserBean;

/**
 * 描述该类- JPA
 *
 * @author zhoufei
 * @class: UserBean
 * @date 2020/10/27 16:09
 * @Verson 1.0 -2020/10/27 16:09
 * @see
 */

@Repository
public class UserDao {
    @Autowired
    JdbcTemplate jdbcTemplate;
    
    // 根据账号查询用户信息
    public UserBean getUserByUsername(String username) {
        String sql = "select * from user where user_name = ?";
        // 连接数据库查询用户
        List<UserBean> list = jdbcTemplate.query(sql, new Object[] { username },
                new BeanPropertyRowMapper<>(UserBean.class));
        if (list != null && list.size() == 1) {
            return list.get(0);
        }
        return null;
    }
    
}